package com.aliothservice.catfish.product.data;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.data.annotation.Id;

public class VehicleService {
	
	public Map<String, Object> mapForSearchResult() {
		Map<String, Object> map = new HashMap<String, Object>();
		
		map.put("id", this.getId());
		map.put("userHash", this.getUserHash());
		map.put("lengthSpec", this.getLengthSpec());
		map.put("temperatureSpec", this.getTemperatureSpec());
		map.put("temperatureSpecList", this.getTemperatureSpecList());
		map.put("fullLoadWeight", this.getFullLoadWeight());
		map.put("fullLoadMass", this.getFullLoadMass());
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		map.put("startDate", formatter.format(this.getStartDate()));
		map.put("untilDate", formatter.format(this.getUntilDate()));
		map.put("originProvince", this.getOriginProvince());
		map.put("originCity", this.getOriginCity());
		map.put("originDistrict", this.getOriginDistrict());
		map.put("destinationProvince", this.getDestinationProvince());
		map.put("destinationCity", this.getDestinationCity());
		map.put("destinationDistrict", this.getDestinationDistrict());
		map.put("price", this.getPrice());
		if (null != this.getIndividual()) {
			map.put("individual", this.getIndividual());
		}
		if (null != this.getEnterprise()) {
			map.put("enterprise", this.getEnterprise());
		}
		map.put("manInChargeName", this.getManInChargeName());
		if (this.getManInChargePhoneNumber().length() != 11) {
			map.put("manInChargePhoneNumber", this.getManInChargePhoneNumber());
		} else {
			String maskedPhoneNumber = String.format("%s*****%s", this.getManInChargePhoneNumber().substring(0, 2), this.getManInChargePhoneNumber().substring(7, 10));
			map.put("manInChargePhoneNumber", maskedPhoneNumber);
		}
		if (null != this.getDeviceSN()) {
			map.put("deviceSN", this.getDeviceSN());
		}
		
		return map;
	}
	
	public Map<String, Object> toMap() {
		Map<String, Object> map = new HashMap<String, Object>();
		
		map.put("id", this.getId());
		map.put("userHash", this.getUserHash());
		map.put("keySpec", this.getKeySpec());
		map.put("lengthSpec", this.getLengthSpec());
		map.put("temperatureSpec", this.getTemperatureSpec());
		map.put("temperatureSpecList", this.getTemperatureSpecList());
		map.put("fullLoadWeight", this.getFullLoadWeight());
		map.put("fullLoadMass", this.getFullLoadMass());
		DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
		map.put("startDate", formatter.format(this.getStartDate()));
		map.put("untilDate", formatter.format(this.getUntilDate()));
		map.put("originProvince", this.getOriginProvince());
		map.put("originCity", this.getOriginCity());
		map.put("originDistrict", this.getOriginDistrict());
		map.put("destinationProvince", this.getDestinationProvince());
		map.put("destinationCity", this.getDestinationCity());
		map.put("destinationDistrict", this.getDestinationDistrict());
		map.put("price", this.getPrice());
		map.put("stock", this.getStock());
		if (null != this.getIndividual()) {
			map.put("individual", this.getIndividual());
		}
		if (null != this.getEnterprise()) {
			map.put("enterprise", this.getEnterprise());
		}
		map.put("manInChargeName", this.getManInChargeName());
		map.put("manInChargePhoneNumber", this.getManInChargePhoneNumber());
		if (null != this.getDeviceSN()) {
			map.put("deviceSN", this.getDeviceSN());
		}
		
		return map;
	}
	
	@Id
	private String id;
	
	// who owns this service
	private String userId;
	private String userHash;
	
	private String keySpec;
	private String lengthSpec;
	private String temperatureSpec;
	private List<String> temperatureSpecList;
	private Integer fullLoadWeight;
	private Integer fullLoadMass;
	
	private Date startDate;
	private Date untilDate;
	private String originProvince;
	private String destinationProvince;
	private String originCity;
	private String destinationCity;
	private String originDistrict;
	private String destinationDistrict;
	private Float price;
	
	private Integer stock;
	
	private Date lastUpdateTime;
	
	private String individual;
	private String enterprise;
	
	private String manInChargeName;
	private String manInChargePhoneNumber;
	
	private String deviceSN;
	
	private LocalDateTime creationDate;

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public Date getLastUpdateTime() {
		return lastUpdateTime;
	}

	public void setLastUpdateTime(Date lastUpdateTime) {
		this.lastUpdateTime = lastUpdateTime;
	}

	public String getKeySpec() {
		return keySpec;
	}

	public void setKeySpec(String keySpec) {
		this.keySpec = keySpec;
	}

	public String getLengthSpec() {
		return lengthSpec;
	}

	public void setLengthSpec(String lengthSpec) {
		this.lengthSpec = lengthSpec;
	}

	public Integer getFullLoadWeight() {
		return fullLoadWeight;
	}

	public void setFullLoadWeight(Integer fullLoadWeight) {
		this.fullLoadWeight = fullLoadWeight;
	}

	public Integer getFullLoadMass() {
		return fullLoadMass;
	}

	public void setFullLoadMass(Integer fullLoadMass) {
		this.fullLoadMass = fullLoadMass;
	}

	public String getTemperatureSpec() {
		return temperatureSpec;
	}

	public void setTemperatureSpec(String temperatureSpec) {
		this.temperatureSpec = temperatureSpec;
	}

	public Integer getStock() {
		return stock;
	}

	public void setStock(Integer stock) {
		this.stock = stock;
	}

	public Date getStartDate() {
		return startDate;
	}

	public void setStartDate(Date startDate) {
		this.startDate = startDate;
	}

	public Date getUntilDate() {
		return untilDate;
	}

	public void setUntilDate(Date untilDate) {
		this.untilDate = untilDate;
	}

	public String getOriginProvince() {
		return originProvince;
	}

	public void setOriginProvince(String originProvince) {
		this.originProvince = originProvince;
	}

	public String getDestinationProvince() {
		return destinationProvince;
	}

	public void setDestinationProvince(String destinationProvince) {
		this.destinationProvince = destinationProvince;
	}

	public String getOriginCity() {
		return originCity;
	}

	public void setOriginCity(String originCity) {
		this.originCity = originCity;
	}

	public String getDestinationCity() {
		return destinationCity;
	}

	public void setDestinationCity(String destinationCity) {
		this.destinationCity = destinationCity;
	}

	public String getUserId() {
		return userId;
	}

	public void setUserId(String userId) {
		this.userId = userId;
	}

	public Float getPrice() {
		return price;
	}

	public void setPrice(Float price) {
		this.price = price;
	}

	public List<String> getTemperatureSpecList() {
		return temperatureSpecList;
	}

	public void setTemperatureSpecList(List<String> temperatureSpecList) {
		this.temperatureSpecList = temperatureSpecList;
	}

	public String getIndividual() {
		return individual;
	}

	public void setIndividual(String individual) {
		this.individual = individual;
	}

	public String getEnterprise() {
		return enterprise;
	}

	public void setEnterprise(String enterprise) {
		this.enterprise = enterprise;
	}

	public String getOriginDistrict() {
		return originDistrict;
	}

	public void setOriginDistrict(String originDistrict) {
		this.originDistrict = originDistrict;
	}

	public String getDestinationDistrict() {
		return destinationDistrict;
	}

	public void setDestinationDistrict(String destinationDistrict) {
		this.destinationDistrict = destinationDistrict;
	}

	public String getUserHash() {
		return userHash;
	}

	public void setUserHash(String userHash) {
		this.userHash = userHash;
	}

	public String getManInChargeName() {
		return manInChargeName;
	}

	public void setManInChargeName(String manInChargeName) {
		this.manInChargeName = manInChargeName;
	}

	public String getManInChargePhoneNumber() {
		return manInChargePhoneNumber;
	}

	public void setManInChargePhoneNumber(String manInChargePhoneNumber) {
		this.manInChargePhoneNumber = manInChargePhoneNumber;
	}

	public String getDeviceSN() {
		return deviceSN;
	}

	public void setDeviceSN(String deviceSN) {
		this.deviceSN = deviceSN;
	}

	public LocalDateTime getCreationDate() {
		return creationDate;
	}

	public void setCreationDate(LocalDateTime creationDate) {
		this.creationDate = creationDate;
	}

}
